Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lossless-json

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lossless-json

Parse JSON without risk of losing numeric information

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
111K
decreased by-28.74%
Maintainers
1
Weekly downloads
 
Created

What is lossless-json?

The lossless-json npm package allows for the parsing and stringifying of JSON data without losing precision for numbers. This is particularly useful for applications that require high precision in numerical data, such as financial calculations or scientific computations.

What are lossless-json's main functionalities?

Parse JSON without losing precision

This feature allows you to parse JSON strings containing large numbers without losing precision. The parsed numbers are represented as LosslessNumber objects.

{"const losslessJSON = require('lossless-json');":"","const jsonString = '{\"bigNumber\": 123456789012345678901234567890}';":"","const parsed = losslessJSON.parse(jsonString);":"","console.log(parsed.bigNumber.toString());":"// '123456789012345678901234567890'"}

Stringify JSON with high precision numbers

This feature allows you to stringify objects containing LosslessNumber instances, ensuring that the precision of large numbers is maintained in the resulting JSON string.

{"const losslessJSON = require('lossless-json');":"","const obj = { bigNumber: losslessJSON.LosslessNumber('123456789012345678901234567890') };":"","const jsonString = losslessJSON.stringify(obj);":"","console.log(jsonString);":"// '{\"bigNumber\":123456789012345678901234567890}'"}

Custom reviver and replacer functions

This feature allows you to use custom reviver and replacer functions during parsing and stringifying, providing more control over how data is processed.

{"const losslessJSON = require('lossless-json');":"","const jsonString = '{\"bigNumber\": 123456789012345678901234567890}';":"","const parsed = losslessJSON.parse(jsonString, (key, value) => {":"","  if (typeof value === 'string' && !isNaN(value)) {":"","    return losslessJSON.LosslessNumber(value);":"","  }":"","  return value;":"","});":"","console.log(parsed.bigNumber.toString());":"// '123456789012345678901234567890'"}

Other packages similar to lossless-json

Keywords

FAQs

Package last updated on 22 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc